package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.ICondition;
import com.example.mymatch.model.Condition;
import com.example.mymatch.service.IConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class IConditionServiceImpl implements IConditionService {
    @Autowired
    private ICondition conditionMapper;
    @Override//添加方法
    public int insertCondition(Condition condition){
        int conditionValue=0;
        //查看当前缴费人员名称不能重复
        Condition condition1=new Condition();
        condition1.setConId(condition.getConId());
        List<Condition> getC =conditionMapper.getAllCondition(condition1);
        if (getC.size()>=1){
            //不可以添加缴费人员名称
            conditionValue=-1;
        }else {
            conditionValue=conditionMapper.insertCondition(condition);
        }
        return conditionValue;
    }
    @Override
    public List<Condition> getAllCondition(Condition condition){return conditionMapper.getAllCondition(condition);}
    @Override
    public int updateCondition(Condition condition){
        int conditionValue=0;
        //判断主键不能为0
        if (condition.getConId()!=0){
            //主键信息必须存在

            //名称不能重复

            conditionValue=conditionMapper.updateCondition(condition);
        }
        return conditionValue;
    }
    @Override
    public int deleteCondition(Condition condition){
        int conditionValue=0;
        //判断主键不能为0
        if (condition.getConId()!=0){
            //主键是否与其他表有关联，如果关联，则先删除其它表的信息，或者给出此条信息不允许被删

            conditionValue=conditionMapper.deleteCondition(condition);
        }
        return conditionValue;
    }

    //单条查询
    @Override
    public Condition getCondition(Condition condition){
        Condition condition1=new Condition();
        if (condition.getConId()!=0){
            condition1=conditionMapper.getCondition(condition);
        }
        return condition1;
    }
}
